home *** CD-ROM | disk | FTP | other *** search
Text File | 2000-09-28 | 2.8 KB | 110 lines | [TEXT/MPS ] |
- /************************************************************
-
- Created: Tuesday, November 6, 1991
- FindServer.cp
- C++ Interface to the AppleTalk Filing Protocol
- M.Vierling
-
-
- Copyright Apple Computer, Inc. 1991-1992
- All rights reserved
-
- ************************************************************/
-
- #include <stream.h>
- #include <Errors.h>
- #include <strings.h>
- #include <AppleTalk.h>
-
- AddrBlock FindServer( char * zoneName, char * serverName )
- {
- MPPPBPtr thePBptr;
- Ptr theRetBuffPtr;
- char * serverType = "AFPServer";
- EntityPtr entityPtr;
- short numGotten;
- Str255 myServerType;
- Str255 myZoneName;
- Str255 myServerName;
- OSErr ErrResult;
- AddrBlock theAddress;
- char AspTimeout = 10;
- char AspRetry = 10;
-
- theAddress.aNet = 0;
- theAddress.aNode = 0;
- theAddress.aSocket = 0;
-
- if ((entityPtr = new EntityName) == nil) {
- return theAddress;
- }
-
- strcpy( (char *)myZoneName, zoneName );
- strcpy( (char *)myServerType, serverType );
- strcpy( (char *)myServerName, serverName );
- c2pstr( (char *)myServerType );
- c2pstr( (char *)myServerName );
- c2pstr( (char *)myZoneName );
-
- NBPSetEntity( (Ptr)entityPtr, (Ptr)myServerName, (Ptr)myServerType, (Ptr)myZoneName );
-
- if ((thePBptr = new MPPParamBlock) == nil) {
- return theAddress;
- }
- if ((theRetBuffPtr = (Ptr)(new char[4096])) == nil) {
- return theAddress;
- }
- thePBptr->NBP.ioRefNum = 0;
- thePBptr->NBP.interval = AspTimeout;
- thePBptr->NBP.count = AspRetry;
- thePBptr->NBP.NBPPtrs.entityPtr = (Ptr)entityPtr;
- thePBptr->NBP.parm.Lookup.retBuffPtr = theRetBuffPtr;
- thePBptr->NBP.parm.Lookup.retBuffSize = 4096;
- thePBptr->NBP.parm.Lookup.maxToGet = 1;
-
- ErrResult = PLookupName( thePBptr, false );
- if (ErrResult)
- {
- cerr << "FindServer: PLookupName Error = " << ErrResult << endl;
- return theAddress;
- }
- ErrResult = thePBptr->NBP.ioResult;
- if (ErrResult)
- {
- cerr << "FindServer: ioResult Error = " << ErrResult << endl;
- return theAddress;
- }
- numGotten = thePBptr->NBP.parm.Lookup.numGotten;
- if (numGotten != 1)
- {
- ErrResult = afpNoServer;
- cerr << "FindServer: Error PLookupName numGotten = " << numGotten << endl;
- return theAddress;
- }
- ErrResult = NBPExtract( theRetBuffPtr, 1, 1, entityPtr, &theAddress );
- if (ErrResult)
- {
- cerr << "FindServer: NBPExtract Error = " << ErrResult << endl;
- return theAddress;
- }
- ErrResult = thePBptr->NBP.ioResult;
- if (ErrResult)
- {
- cerr << "FindServer: ioResult Error = " << ErrResult << endl;
- return theAddress;
- }
-
- // cerr << "Server name:";
- // cerr << p2cstr( (*entityPtr).objStr ) << endl;
- // cerr << "Net: " << (long)theAddress.aNet << endl;
- // cerr << "Node: " << (long)theAddress.aNode << endl;
- // cerr << "Socket: " << (long)theAddress.aSocket << endl;
-
- delete entityPtr;
- delete thePBptr;
- delete [] theRetBuffPtr;
-
- return theAddress;
- }
-
-